//
//  BaseTabBarController.m
//  聊吧
//
//  Created by 刘洋 on 16/6/13.
//  Copyright © 2016年 刘洋. All rights reserved.
//

#import "BaseTabBarController.h"



@interface BaseTabBarController ()

@end

@implementation BaseTabBarController

-(void)dealloc{
    
    [_chatBaNaVC release];
    [_chatBaNaVC release];
    [_discoveryNaVC release];
    [_mineNaVC release];
    [super dealloc];
}


+(BaseTabBarController *)shareTabBarController{
    static BaseTabBarController *tabBar = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        tabBar = [[BaseTabBarController alloc]init];
    });
    return tabBar;
    
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    ChatBaViewController *chatBaVC = [[ChatBaViewController alloc]init];
    self.chatBaNaVC = [[UINavigationController alloc]initWithRootViewController:chatBaVC];
     chatBaVC.navigationController.navigationBar.translucent = NO;
    [chatBaVC release];
    
    
   ContactsViewController *contactsVC = [[ContactsViewController alloc]init];
    self.contactsNaVC = [[UINavigationController alloc]initWithRootViewController:contactsVC];
     contactsVC.navigationController.navigationBar.translucent = NO;
    [contactsVC release];
    
    DiscoveryViewController *discoveryVC = [[DiscoveryViewController alloc]init];
    self.discoveryNaVC = [[UINavigationController alloc]initWithRootViewController:discoveryVC];
     discoveryVC.navigationController.navigationBar.translucent = NO;
    [discoveryVC release];
    
    MineViewController *mineVC = [[MineViewController alloc]init];
    self.mineNaVC = [[UINavigationController alloc]initWithRootViewController:mineVC];
    mineVC.navigationController.navigationBar.translucent = NO;
    [mineVC release];
    
    
    self.viewControllers = @[_chatBaNaVC,_contactsNaVC,_discoveryNaVC,_mineNaVC];
    [_chatBaNaVC release];
    [_contactsNaVC release];
    [_discoveryNaVC release];
    [_mineNaVC release];
   
    self.tabBarController.tabBar.translucent = NO;
    
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(contactsBadgeValue:) name:@"contactsBadgeValue" object:nil];
    
#pragma mark -- 取消TabBar半透明状态
    self.tabBar.translucent = NO;
    
    
    [self insertChildViewController:_chatBaNaVC title:@"聊吧" imageName:@"chatBa" selectedImageName:nil tabBar:self.tabBar index:0];
    
    
    [self insertChildViewController:_contactsNaVC title:@"联系人" imageName:@"communication" selectedImageName:nil tabBar:self.tabBar index:1];
    
    
     [self insertChildViewController:_discoveryNaVC title:@"发现" imageName:@"Discovery" selectedImageName:nil tabBar:self.tabBar index:2];
    
    [self insertChildViewController:_mineNaVC title:@"我的" imageName:@"mine" selectedImageName:nil tabBar:self.tabBar index:3];
    
    self.tabBar.tintColor = RGBAColor(200, 100, 100);

    
    
    
    
    
    
    
    
    // Do any additional setup after loading the view.
}



#pragma mark -- 设置tabBar视图的方法
-(void)insertChildViewController:(UIViewController *)childVC title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName tabBar:(UITabBar *)tabBar index:(NSUInteger)index{
    
    childVC.title = title;

    UITabBarItem *item = [tabBar.items objectAtIndex:index];
    
    UIImage *image = [UIImage imageNamed:imageName];
    
    UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
    
    [item setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    [item setSelectedImage:[selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    
}



-(void)contactsBadgeValue:(NSNotification *)noti{
    
    self.contactsNaVC.tabBarItem.badgeValue = [noti object];
    
    
    
}








- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
